package com.lys.mapper;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public class MyBatisUtil {
	
	private static SqlSessionFactory factory = null;
	private static SqlSession session = null;
	
	public static SqlSession getSession() {
		InputStream is = null;
		try {
			is = Resources.getResourceAsStream("mybatis.xml");
			factory = new SqlSessionFactoryBuilder().build(is);
			return session = factory.openSession(true);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	public static void closeSession(SqlSession session) {
		if (session != null) {
			session.close();
		}
		
	}

}
